use strict;

sub make_sym_table($)
{
	my $file = shift;
	my $cnt = 0;
	my %sym = ();

	open my $fh, $file or die;
	binmode($fh, ':encoding(utf8)');

	while ( <$fh> )  {
		$cnt ++;
		my $ln = $_;
		m/^(\S+)\t(\S+)$/;
		if ($2)  {
			$sym{$2} = 1;
		}
	}
	close $fh;
	return %sym;
}

# input:
# 1. a reference to an array
# 2. output file name
sub output($$)
{
	my $rf = shift;
	my $ofile = shift;
	open my $ofh, "> $ofile" or die;
	print "output to: $ofile\n";
	binmode($ofh, ':encoding(utf8)');
	print $ofh "# this file is outputed by ''mksymtable.pl''\n";
	print $ofh "# first colume is unicode code point U+[0-9a-fA-F]+\n";

	my @arr = @$rf;
	foreach (sort @arr)  {
		printf $ofh "U+%X\t%s\n", ord($_), $_;
	}

	close $ofh;
}

sub main()
{
	my %sym = ();
	%sym = make_sym_table('sym.txt');
	my @arr = keys(%sym);
	output(\@arr, 'symout.txt');
}

main;
